﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using School;

namespace TestSchool
{
    [TestClass]
    public class CourseTest
    {
        [TestMethod]
        public void TestJoin()
        {
            string name1 = "Veselin";
            int number1 = 10000;
            Student student1 = new Student(name1, number1);
            string name2 = "Toni";
            int number2 = 10001;
            Student student2 = new Student(name2, number2);
            Course course = new Course();
            course.Join(student1);
            course.Join(student2);

            Assert.IsTrue(course.StudentsCount == 2);
            Assert.AreEqual(name1, course[student1.UniqueNumber].Name);
            Assert.AreEqual(number1, course[student1.UniqueNumber].UniqueNumber);
            Assert.AreEqual(name2, course[student2.UniqueNumber].Name);
            Assert.AreEqual(number2, course[student2.UniqueNumber].UniqueNumber);
        }

        [TestMethod]
        [ExpectedException(typeof(Exception))]
        public void TestJoin_TooManyStudentsInCourse()
        {
            Course course = new Course();
            for (int i = 0; i <= Course.MAX_STUDENTS_COUNT; i++)
            {
                string name = "Veselin";
                int number = i + 10000;
                Student student = new Student(name, number);

                course.Join(student);
            }
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestJoin_AddExistingStudent()
        {
            string name = "Veselin";
            int number = 10000;
            Student student = new Student(name, number);
            Course course = new Course();

            course.Join(student);
            course.Join(student);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestJoin_AddNullStudent()
        {
            //Student student = null;
            Course course = new Course();

            course.Join(null);
        }

        [TestMethod]
        public void TestLeave()
        {
            string name = "Veselin";
            int number = 10000;
            Student student = new Student(name, number);
            Course course = new Course();
            course.Join(student);
            course.Leave(student);

            Assert.IsTrue(course.StudentsCount == 0);
        }

        [TestMethod]
        [ExpectedException(typeof(Exception))]
        public void TestLeave_LeaveEmptyCourse()
        {
            string name = "Veselin";
            int number = 10000;
            Student student = new Student(name, number);
            Course course = new Course();

            course.Leave(student);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestLeave_LeaveNotExistingStudent()
        {
            string name = "Veselin";
            int number = 10000;
            Student student = new Student(name, number);
            Course course = new Course();
            course.Join(student);
            string otherStudentName = "Antonia";
            int otherStudentNumber = 10001;
            Student otherStudent = new Student(otherStudentName, otherStudentNumber);

            course.Leave(otherStudent);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestLeave_LeaveNullStudent()
        {
            string name = "Veselin";
            int number = 10000;
            Student student = new Student(name, number);
            Course course = new Course();
            course.Join(student);

            course.Leave(null);
        }
    }
}
